/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "posTab")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "POSTab.findOpenTabs", query = "SELECT p FROM POSTab p WHERE p.closedTab = 'false' ORDER BY p.tabName ASC"),
    @NamedQuery(name = "POSTab.findAll", query = "SELECT s FROM POSTab s ORDER BY s.tabName ASC")})
public class POSTab implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "tabID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "openEnded")
    private boolean openEnded;
    @Basic(optional = false)
    @NotNull
    @Column(name = "closedTab")
    private boolean closedTab;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 100)
    @Column(name = "tabName")
    private String tabName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "tabTotalUsed")
    private float totalUsed;
    @Basic(optional = false)
    @NotNull
    @Column(name = "tabTotalRemaining")
    private float totalRemaining;
    @OneToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
    @JoinTable(
        name="posJTTabToSaleTab",
        joinColumns={ @JoinColumn(name="tabID", referencedColumnName="tabID")},
        inverseJoinColumns={ @JoinColumn(name="saleTabID", referencedColumnName="saleTabID", unique=true)}
    )
    private List<POSSaleTab> saleCollection;

    public POSTab() {
    }

    public POSTab(Integer id) {
        this.id = id;
    }

    public POSTab(Integer id, boolean openEnded, boolean closedTab, String tabName, float totalUsed, float totalRemaining) {
        this.id = id;
        this.openEnded = openEnded;
        this.closedTab = closedTab;
        this.tabName = tabName;
        this.totalUsed = totalUsed;
        this.totalRemaining = totalRemaining;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public boolean isOpenEnded() {
        return openEnded;
    }

    public void setOpenEnded(boolean openEnded) {
        this.openEnded = openEnded;
    }

    public boolean isClosedTab() {
        return closedTab;
    }

    public void setClosedTab(boolean closedTab) {
        this.closedTab = closedTab;
    }

    public String getTabName() {
        return tabName;
    }

    public void setTabName(String tabName) {
        this.tabName = tabName;
    }

    public float getTotalUsed() {
        return totalUsed;
    }

    public void setTotalUsed(float totalUsed) {
        this.totalUsed = totalUsed;
    }

    public float getTotalRemaining() {
        return totalRemaining;
    }

    public void setTotalRemaining(float totalRemaining) {
        this.totalRemaining = totalRemaining;
    }

    public List<POSSaleTab> getSaleCollection() {
        return saleCollection;
    }

    public void setSaleCollection(List<POSSaleTab> saleCollection) {
        this.saleCollection = saleCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSTab)) {
            return false;
        }
        POSTab other = (POSTab) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.postab[ id=" + id + " ]";
    }
}
